package com.example.test.compents;


import com.example.test.common.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.validation.ValidationException;

@Slf4j
@RestControllerAdvice
public class ExceptionAdvice {

    /**
     * ValidationException
     */
    @ExceptionHandler(ValidationException.class)
    public ResultBody handleValidationException(ValidationException e) {
        return ResultBody.fail(e.getCause().getMessage());
    }


    @ExceptionHandler(Exception.class)
    public ResultBody handleException(Exception e) {
        log.error(e.getMessage(), e);
        return ResultBody.fail("系统繁忙,请稍后再试");
    }

}
